package com.tanhua.dubbo.api;

import cn.hutool.core.date.DateUtil;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.tanhua.dubbo.mappers.AnnouncementMapper;
import com.tanhua.model.domain.Announcement;

import org.apache.dubbo.config.annotation.DubboService;
import org.springframework.beans.BeanUtils;
import org.springframework.beans.factory.annotation.Autowired;

import java.util.List;
import java.util.stream.Collectors;


@DubboService
public class AnnouncementApiImpl implements AnnouncementApi{

    @Autowired
    private AnnouncementMapper announcementMapper;



    //公告列表
    @Override
    public Page<Announcement> findannouncements(Integer page, Integer pagesize) {
        Page<Announcement> ipage = new Page<>(page,pagesize);
        QueryWrapper<Announcement> qw = new QueryWrapper<>();
        qw.orderByDesc("created");
        Page<Announcement> announcementPage = announcementMapper.selectPage(ipage,qw);
        List<Announcement> records = announcementPage.getRecords();
        records.stream().map(record->{
            record.setCreateDate(DateUtil.format(record.getCreated(),"yyyy-MM-dd HH:mm"));
            return record;
        }).collect(Collectors.toList());
        announcementPage.setRecords(records);
        return announcementPage;
    }
}
